package com.alinesno.cloud.common.core.config;

import java.util.concurrent.Executor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 添加异常执行方法
 * @author LuoAnDong
 * @since 2019年6月19日 下午9:17:19
 */
@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {
    
    /**
     * 异步执行线程池 
     */
    @Override
    public Executor getAsyncExecutor() {
    	
        //定义线程池
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        
        //核心线程数
        taskExecutor.setCorePoolSize(20);
        
        //线程池最大线程数
        taskExecutor.setMaxPoolSize(100);
        
        //线程队列最大线程数
        taskExecutor.setQueueCapacity(10);
        
        //初始化
        taskExecutor.initialize();
        
        return taskExecutor;
    }

	@Override
	public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
		return null;
	}
}